package utils.jaxb;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.XmlRootElement;

import param.pub.Publicrequest;
import param.pub.Publicresponse;

public class PublicJsonUtil {
	public static Publicrequest newPublicrequest() {
		Publicrequest publicrequest = new Publicrequest();
		publicrequest.setAskorgcode("NMGWEB");
		publicrequest.setAskorgname("内蒙古电子客票网");
//		publicrequest.setTargetorgcode("");
//		publicrequest.setAsktime(new Date());
		publicrequest.setAsktime((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
		publicrequest.setVersion("1.0.0");
		publicrequest.setSignmsg("signmsg");
		return publicrequest;
	}

	public static Publicresponse newPublicresponse() {
		Publicresponse publicresponse = new Publicresponse();
//		publicresponse.setReturntime(new Date());// 返回时间
		publicresponse.setReturntime((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));// 返回时间
		publicresponse.setVersion("1.0.0");// 接口版本号
		publicresponse.setSignmsg("signmsg");//签名
		return publicresponse;
	}

	public static String toXml(Object obj) {
		try {
			return XmlUtil.toXml(obj);
		} catch (Exception e) {
			String rootEleName = null;
			XmlRootElement annoclass = obj.getClass().getAnnotation(
					XmlRootElement.class);
			if (annoclass != null) {
				rootEleName = annoclass.name();
			}
			if (rootEleName == null) {
				rootEleName = obj.getClass().getName();
			}
			return " <"
					+ rootEleName
					+ "><PublicInfo><VC_BUSINESS_ID>testBN001</VC_BUSINESS_ID><VC_STATION_ID>testST001</VC_STATION_ID><VC_TERMINAL_NO>testTN001</VC_TERMINAL_NO><VC_USER_ID>testUS001</VC_USER_ID><VC_RE_CODE>201</VC_RE_CODE><VC_RE_TX>对象转换成XML异常</VC_RE_TX><DT_REQUEST_TIME>"
					+ new Date()
					+ "</DT_REQUEST_TIME><VC_VERSION>1.0</VC_VERSION><VC_SIGN>163f79d4785486d2a9520cf6700a0818</VC_SIGN></PublicInfo></"
					+ rootEleName + ">";
		}
	}
}
